
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.interfaces.workflow.browser.Browser" %>

<%@ page import="java.util.*" %>
<%@ include file="/systeminfo/init_wev8.jsp" %>
<jsp:useBean id="RecordSet" class="weaver.conn.RecordSet" scope="page" />
<LINK href="/css/Weaver_wev8.css" type=text/css rel=STYLESHEET>
<link rel="stylesheet" type="text/css" href="/js/extjs/resources/css/ext-all_wev8.css" />
<link rel="stylesheet" type="text/css" href="/js/extjs/resources/css/xtheme-gray_wev8.css" />
<style type="text/css">
<!--
.search-button {
    background-image:url(/images_frame/search_dot_wev8.gif) !important;
}
-->
</style>

<form name="frmCenter"  id="frmCenter" action="javascript:void(0);" method="post">
	<input type='hidden' name='nodenames' id='nodenames'>
	<input type='hidden' name='nodeids'  id='nodeids'>
	<input type='hidden' name='checkchange' id='checkchange'>
	<input type="hidden"  id="btnSave"  onclick='onGetChecked()'>
	<div id="tree"></div>
<form>
<%@ include file="/systeminfo/RightClickMenuConent_wev8.jsp" %>
<%@ include file="/systeminfo/RightClickMenu_wev8.jsp" %>

<script type="text/javascript" src="/js/extjs/adapter/ext/ext-base_wev8.js"></script>
<script type="text/javascript" src="/js/extjs/ext-all_wev8.js"></script>
<!-- Files needed for SwfUploaderPanel -->

<%
String type = Util.null2String(request.getParameter("browsertype"));
String ismutil = Util.null2String(request.getParameter("ismutil"));//1：单选；2：多选
String othercallback = Util.null2String(request.getParameter("othercallback"));
String currenttime = Util.null2String(request.getParameter("currenttime"));
String workflowid = Util.getIntValue(request.getParameter("workflowid"),-1)+"";
Browser browser=(Browser)StaticObj.getServiceByFullname(type, Browser.class);
String tempname = browser.getName();
if("".equals(tempname))
	tempname = SystemEnv.getHtmlLabelName(83327 ,user.getLanguage());//自定义浏览框
String href = Util.null2String(browser.getHref());
String outpage = Util.null2String(browser.getOutPageURL());
String search = Util.null2String(browser.getSearch());
//String ismutil = browser.getIsmutil();
String parentfield = browser.getParentfield();
String from = Util.null2String(browser.getFrom());
//if(from.equals("2")){
	browser.initBaseBrowser("",type,from);
//}
%>

<SCRIPT LANGUAGE="JavaScript">
	$(function(){
		try{
			parent.setTabObjName("<%=tempname %>");
		}catch(e){}
	});
	var parentWin = window.parent.parent.getParentWindow(parent);
	var dialog = window.parent.parent.getDialog(parent);
</SCRIPT>
<%
//System.out.println("parentfield : "+parentfield);
if(!"".equals(parentfield))
{
%>
<SCRIPT LANGUAGE=VBS>
Sub returnData(returnstr)
   window.parent.returnvalue = returnstr
   window.parent.Close
End Sub
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
	 var nodetype = "<%=type%>";
	 var Tree_Category;
	 var checkchange = false;
	 
	 Ext.onReady(function() {
			Ext.BLANK_IMAGE_URL = '/js/extjs/resources/images/default/s_wev8.gif';
		   // Define Tree.
			
			showTree();
	});
	function getSelectValue(tree) {
	    var ids = "";  
	    var names = "";  
	    var b = tree.getChecked();   
        var checkid = new Array;// 存放选中id的数组   
        var checkname = new Array;// 存放选中name的数组   
        for (var i = 0; i < b.length; i++) {   
             checkname.push(b[i].text);// 添加id到数组 
             checkid.push(b[i].id);
        }
        //alert(checkid.toString());
        
	    var array = new Array();  
	    array[0] = checkid.toString();  
	    array[1] = checkname.toString();
	    
	    return array;  
	}
	
	function showTree() {  
	    var root = new Ext.tree.AsyncTreeNode( {  
	        text : "<%=SystemEnv.getHtmlLabelName(124879 ,user.getLanguage())%>",  
	        draggable : false,  
	        id : "root"
	    });
	    var selectnode = null;
	    
	    var currenttime = <%=currenttime%>;//(new Date()).valueOf();
	    var Tree_Category_Loader = new Ext.tree.TreeLoader({
					baseParams:{"checked":'false',"type":'<%=type%>','currenttime':currenttime,'workflowid':'<%=workflowid%>'},
					dataUrl   :"CommonTreeCenterTreeData.jsp",
					baseAttrs : {
		                uiProviders : Ext.ux.TreeCheckNodeUI  
		            } 
				});
	    var tree = new Ext.tree.TreePanel({
	        id:'tree', 
	        useArrows:true,
	        rootVisible : true,  
	        height : 520,  
	        //autoHeight:true,   
	        draggable : false,  
	        //width:width - 16,   
	        margins : '0 0 0 0',  
	        autoScroll : true,  
	        animate : true,  
	        enableDD : true,  
	        containerScroll: true,
	        root : root, 
	        loader : Tree_Category_Loader  
	    });
	    <%if("2".equals(ismutil)){%>
		tree.on('checkchange', function(node, checked) {
		    Tree_Category_Loader.baseParams.checked=checked;
            node.expand();
            node.attributes.checked = checked;   
            node.eachChild(function(child) {
               child.ui.toggleCheck(checked);
               child.attributes.checked = checked;
               child.fireEvent('checkchange', child, checked);   
           });   
        }, tree); 
        <%}else{%>
        tree.on('checkchange', function(node, checked) {
	    	Tree_Category_Loader.baseParams.checked="false";
            node.expand();
            //监听改变选择框时候的事件
            var checkedNodes = tree.getChecked();//获取当前以选择的节点信息
            
            for(var i=0;i<checkedNodes.length;i++){
               var n = checkedNodes[i];
               //alert("checkedNodes : node : "+node.id+"   n : "+n.id);
               if(node.id != n.id&&checked){
                   n.ui.toggleCheck(false);
               	   n.attributes.checked = false;
               }
            }
            node.attributes.checked = checked;
       }, tree);
        <%}%>
	    var win = new Ext.Window({
	        title : '<%=SystemEnv.getHtmlLabelName(18214 ,user.getLanguage())%>',  
	        id : 'extwin',  
	        plain:true,       
	        height : 520,  
	        width:540,  
	        //autoScroll : true,  
	        layout:"form",  
	        labelWidth:60,  
	        shadow :false,  
	        shadowOffset:0,  
	        draggable : false, 
	        resizable: false,
	        animCollapse:true,
	        closable:false,
	        modal : true, // 遮罩  
	        items : tree          
	    });  
	      
	    var ok = new Ext.Button({  
	        id:"ok",  
	        text:"<%=SystemEnv.getHtmlLabelName(826 ,user.getLanguage())%>",
	        handler: selectok
	    });  
	    function selectok() {
            var array = getSelectValue(tree);  //选中值array[0] 为ID，array[1]为名称,格式都为"xx,xx"  
            if(array[0].length == 0){  
                Ext.Msg.alert("<%=SystemEnv.getHtmlLabelName(558 ,user.getLanguage())%>","<%=SystemEnv.getHtmlLabelName(124877 ,user.getLanguage())%>")  
                return;  
            }
            try
            {
	            var returnjson = {id:array[0], name:array[1]};
		        //window.parent.returnValue  = returnjson;
	            Ext.getCmp("extwin").close();
	            //window.parent.close(); 
	            if(dialog){
					 try{
					     dialog.callback(returnjson);
					 }catch(e){}
					 
					 try{
					     dialog.close(returnjson);
					 }catch(e){}
				}else{
					<%if(!"1".equals(othercallback)){%>
			    		window.parent.returnValue=returnjson;
						window.parent.close();
			    	<%}else{%>
			    		returnData("{'id':'"+array[0]+"','name':'"+array[1]+"'}")
			    	<%}%>
					
				}
            }
            catch(e)
            {
            	Ext.getCmp("extwin").close();
            }
        }
	    var clear = new Ext.Button({  
	        id:"clear",  
	        text:"<%=SystemEnv.getHtmlLabelName(311 ,user.getLanguage())%>",
	        handler: clear
	    });  
	    function clear(){
       		//  var array = getSelectValue();;  //选中值array[0 为ID，array[1]为名称,格式都为"xx,xx"          
            try
            {
	            var returnjson = {id:"", name:""};
		        //window.parent.returnValue  = returnjson;
	            //Ext.getCmp("extwin").close();
	            //window.parent.close(); 
	            Ext.getCmp("extwin").close();
	            //window.parent.close(); 
	            if(dialog){
					 try{
					     dialog.callback(returnjson);
					 }catch(e){}
					 
					 try{
					     dialog.close(returnjson);
					 }catch(e){}
				}else{
					<%if(!"1".equals(othercallback)){%>
			    		window.parent.returnValue=returnjson;
						window.parent.close();
			    	<%}else{%>
			    		returnData("{'id':'','name':''}");
			    	<%}%>
				}
            }
            catch(e)
            {
            	Ext.getCmp("extwin").close();
            }
        }
	    
	    win.addButton(ok);  
	    win.addButton(clear);
	    win.show(document); 
	    root.expand();
	}
</script>
<%}else{%>
<%=SystemEnv.getHtmlLabelName(83577,user.getLanguage())%>
<%}%>